package com.bjpowernode.oa.utils;

import java.sql.*;
import java.util.ResourceBundle;

public class DBUtil {
    private static ResourceBundle bundle=ResourceBundle.getBundle("resource.jdbc");
    private static String driver=bundle.getString("driver");
    private static String url=bundle.getString("url");
    private static String user=bundle.getString("user");
    private static String password=bundle.getString("password");
    static{
        try{
            Class.forName(driver);
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }

    }
    public static Connection getConnection() throws SQLException {
        Connection conn=DriverManager.getConnection(url,user,password);
        return conn;
    }
    public static void close(Connection conn, Statement ps, ResultSet rs) throws SQLException {
        if (rs != null) {


            try {
                rs.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }


        }
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (conn != null) {

            try {
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }
    }
}
